package entities;

import java.io.Serializable;
import java.util.Date;

/**
 * @author Omri Barda		039725890 
 * @author Amit Joseph		034608547
 * @author Gilad Shpigel  	300162393
 * @author Elad Elbaz		040539959
 * @version June 2012
 */

/**
 * Question construction.
 */
public class Question implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	final public static int CREATE = 1;
	final public static int DELETE = 2;
	final public static int GET = 3;
	final public static int ERROR = 99999;

	private Integer qID;
	private String qText;
	private Date qDate;
	private int qCreator;
	private String qInstructions;
	private String correctAns; // Always answer number 1 in the DataBase
	private String answerA; // Always answer number 2 in the DataBase
	private String answerB; // Always answer number 3 in the DataBase
	private String answerC; // Always answer number 4 in the DataBase
	private Integer SubjectID;

	/**
	 * empty constructor
	 */
	public Question() {
	}

	// ------------------
	// Setters & Getters
	// ------------------
	/**
	 * 
	 * @return the question ID
	 */
	public Integer getqID() {
		return qID;
	}

	/**
	 * 
	 * @param qID
	 *            of the question
	 * @return whether the ID is legal
	 */
	public Boolean setqID(Integer qID) {
		if ((qID > 999) && (qID <= 99999)) {
			this.qID = new Integer(qID.intValue() % 1000);
			this.SubjectID = new Integer(qID.intValue() / 1000);
		} else if ((qID >= 0) && (qID < 1000))
			this.qID = qID;
		else
			return false;
		return true;
	}

	/**
	 * 
	 * @return the question text
	 */
	public String getqText() {
		return qText;
	}

	/**
	 * 
	 * @param qText
	 *            of the question
	 */
	public void setqText(String qText) {
		this.qText = qText;
	}

	/**
	 * 
	 * @return the question date
	 */
	public Date getqDate() {
		return qDate;
	}

	/**
	 * 
	 * @param date
	 *            of question
	 */
	public void setqDate(java.util.Date date) {
		this.qDate = date;
	}

	/**
	 * 
	 * @return the question creator
	 */
	public int getqCreator() {
		return qCreator;
	}

	/**
	 * 
	 * @return the question instructions
	 */
	public String getqInstructions() {
		return qInstructions;
	}

	/**
	 * 
	 * @param qInstructions
	 *            of the question
	 */
	public void setqInstructions(String qInstructions) {
		this.qInstructions = qInstructions;
	}

	/**
	 * 
	 * @return the correct answer
	 */
	public String getCorrectAns() {
		return correctAns;
	}

	/**
	 * 
	 * @param correct
	 *            Answer of the question
	 */
	public void setCorrectAns(String correctAns) {
		this.correctAns = correctAns;
	}

	/**
	 * 
	 * @return answer a
	 */
	public String getAnswerA() {
		return answerA;
	}

	/**
	 * 
	 * @param answerA
	 *            of the question
	 */
	public void setAnswerA(String answerA) {
		this.answerA = answerA;
	}

	/**
	 * 
	 * @return answer b
	 */
	public String getAnswerB() {
		return answerB;
	}

	/**
	 * 
	 * @param answerB
	 *            of the question
	 */
	public void setAnswerB(String answerB) {
		this.answerB = answerB;
	}

	/**
	 * 
	 * @return answer c
	 */
	public String getAnswerC() {
		return answerC;
	}

	/**
	 * 
	 * @param answerC
	 *            of the question
	 */
	public void setAnswerC(String answerC) {
		this.answerC = answerC;
	}

	/**
	 * 
	 * @param userID
	 *            of the question
	 */
	public void setqCreator(int userID) {
		this.qCreator = userID;

	}

	/**
	 * 
	 * @return the question subject ID
	 */
	public Integer getSubjectID() {
		return SubjectID;
	}

	/**
	 * 
	 * @param subjectID
	 *            of the question
	 */
	public void setSubjectID(Integer subjectID) {
		SubjectID = subjectID;
	}

	/**
	 * converting the question to string
	 */
	public String toString() {
		return "Question No." + SubjectID + qID + "\t " + qDate + "\n"
				+ "Created by: " + qCreator + "\nInstructions:" + qInstructions
				+ "\n" + qText + "\n" + "Correct Answer:" + correctAns
				+ "\nWrong Answer No.1:" + answerA + "\nWrong Answer No.2:"
				+ answerB + "\nWrong Answer No.3:" + answerC + "\n";
	}
}
